// import Compiler from "./compiler";

const Compiler = require('./compiler')

function webpack(config){

    const shellOptions = process.argv.slice(2).reduce((config,arg)=>{
        let [key,value] = arg.split('=')
        config[key.slice(2)] = value
        return config
    },{})
    const finallOptions =  {...config,...shellOptions}
    const compiler = new Compiler(finallOptions)

    // 创建完comppiler后  挂载插件

    finallOptions.plugins.forEach(plugin => {
        plugin.apply(compiler)
    });


    return compiler
} 

module.exports = webpack